/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package group6;

import java.awt.Font;
import java.awt.GraphicsEnvironment;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.ListModel;
import javax.swing.UIManager;

/**
 *
 * @author Nhi Rambo
 */
public class FontForm extends javax.swing.JFrame {

    WikiLineNote wiKi;

    /**
     * Creates new form FontForm
     */
    public FontForm() {
        setUIManager();
        initComponents();
        setLocation(200, 100);
        setVisible(true);
        setModel_TFFont();
        setFontStyle();
        setFontSize();
    }

    public void setForm(WikiLineNote wiki) {
        wiKi = wiki;
    }

    private void setModel_TFFont() {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fontname = ge.getAvailableFontFamilyNames();
        DefaultListModel model = new DefaultListModel();
        for (int i = 0; i < fontname.length; i++) {
            model.addElement(fontname[i]);
        }
        lsfont.setModel(model);
    }

    private void setFontStyle() {
        DefaultListModel model = new DefaultListModel();
        model.addElement("Plain");
        model.addElement("Bold");
        model.addElement("Italic");
        lsfontstyle.setModel(model);
    }

    private void setFontSize() {
        DefaultListModel model = new DefaultListModel();
        for (int i = 8; i <= 20; i++) {
            model.addElement(i + "");
        }
        lsfontsize.setModel(model);
    }

    private void setUIManager() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        tffontname = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        tffontstyle = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        tffontsize = new javax.swing.JTextField();
        jScrollPane4 = new javax.swing.JScrollPane();
        lsfont = new javax.swing.JList();
        jScrollPane1 = new javax.swing.JScrollPane();
        lsfontstyle = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        lsfontsize = new javax.swing.JList();
        btok = new javax.swing.JButton();
        btcalcel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jLabel1.setText("Font:");

        jLabel2.setText("Font Style:");

        jLabel3.setText("Size:");

        lsfont.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lsfontMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(lsfont);

        lsfontstyle.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lsfontstyleMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(lsfontstyle);

        lsfontsize.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lsfontsizeMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(lsfontsize);

        btok.setText("OK");
        btok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btokActionPerformed(evt);
            }
        });

        btcalcel.setText("Cancel");
        btcalcel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btcalcelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
                            .addComponent(jLabel1)
                            .addComponent(tffontname))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(57, 57, 57)
                                .addComponent(jLabel3))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                    .addComponent(tffontstyle, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(tffontsize, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(206, 206, 206)
                        .addComponent(btok, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btcalcel)))
                .addContainerGap(31, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tffontname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tffontstyle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tffontsize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btok)
                    .addComponent(btcalcel))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void lsfontMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lsfontMouseClicked
        tffontname.setText(lsfont.getSelectedValue().toString());
    }//GEN-LAST:event_lsfontMouseClicked

    private void lsfontstyleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lsfontstyleMouseClicked
        tffontstyle.setText(lsfontstyle.getSelectedValue().toString());
    }//GEN-LAST:event_lsfontstyleMouseClicked

    private void lsfontsizeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lsfontsizeMouseClicked
        tffontsize.setText(lsfontsize.getSelectedValue().toString());
    }//GEN-LAST:event_lsfontsizeMouseClicked

    private void btcalcelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btcalcelActionPerformed
        this.dispose();
    }//GEN-LAST:event_btcalcelActionPerformed

    private boolean checkEmpty() {
        boolean result = false;
        if (tffontname.getText().equals("") || tffontstyle.getText().equals("") || tffontsize.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "This isn't enough", "Error", JOptionPane.ERROR_MESSAGE);
            result = true;
        }
        return result;
    }
    private void btokActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btokActionPerformed
        if (!checkEmpty()) {
            wiKi.setFontText(tffontname.getText().toString(), tffontstyle.getText().toString(), tffontsize.getText().toString());
            this.dispose();
        }
    }//GEN-LAST:event_btokActionPerformed

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(FontForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(FontForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(FontForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(FontForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the form */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new FontForm().setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btcalcel;
    private javax.swing.JButton btok;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JList lsfont;
    private javax.swing.JList lsfontsize;
    private javax.swing.JList lsfontstyle;
    private javax.swing.JTextField tffontname;
    private javax.swing.JTextField tffontsize;
    private javax.swing.JTextField tffontstyle;
    // End of variables declaration//GEN-END:variables
}
